﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="MessagesScrollBar" TargetType="{x:Type ScrollBar}">
        <Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollBar}">
                    <ControlTemplate.Resources>
                        <Style x:Key="ArrowButton" TargetType="{x:Type RepeatButton}">
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                        <Grid Background="Transparent">
                                            <Viewbox x:Name="content" Margin="2">
                                                <Grid>
                                                    <Path x:Name="imageFill" Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L 531.107,321.943 Z" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" IsHitTestVisible="False">
                                                        <Path.Fill>
                                                            <LinearGradientBrush StartPoint="0, 0.5" EndPoint="1, 0.5">
                                                                <GradientStop Offset="0" Color="#66CCFF"/>
                                                                <GradientStop Offset="0.499" Color="#66CCFF"/>
                                                                <GradientStop Offset="0.501" Color="#6666FF"/>
                                                                <GradientStop Offset="1" Color="#6666FF"/>
                                                            </LinearGradientBrush>
                                                        </Path.Fill>
                                                    </Path>
                                                    <Path Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L 531.107,321.943 Z" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" IsHitTestVisible="False" StrokeThickness="1" Fill="Transparent" Opacity="0.8">
                                                        <Path.Stroke>
                                                            <LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1">
                                                                <GradientStop Offset="0" Color="Gray"/>
                                                                <GradientStop Offset="0.8" Color="Gray"/>
                                                                <GradientStop Offset="1" Color="Black"/>
                                                            </LinearGradientBrush>
                                                        </Path.Stroke>
                                                    </Path>
                                                </Grid>
                                            </Viewbox>
                                            <Rectangle x:Name="ArrowStroke" Fill="Gray" Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="4, 0, 4, 4" Visibility="Hidden"/>
                                        </Grid>

                                        <ControlTemplate.Triggers>
                                            <Trigger Property="Tag" Value="Up">
                                                <Setter TargetName="content" Property="LayoutTransform">
                                                    <Setter.Value>
                                                        <TransformGroup>
                                                            <RotateTransform Angle="180"/>
                                                            <ScaleTransform ScaleX="-1"/>
                                                        </TransformGroup>
                                                    </Setter.Value>
                                                </Setter>
                                            </Trigger>

                                            <Trigger Property="Tag" Value="ToTheEnd">
                                                <Setter TargetName="ArrowStroke" Property="Visibility" Value="Visible"/>
                                            </Trigger>

                                            <Trigger Property="IsMouseOver" Value="true">
                                                <Setter TargetName="imageFill" Property="Fill">
                                                    <Setter.Value>
                                                        <LinearGradientBrush StartPoint="0, 0.5" EndPoint="1, 0.5">
                                                            <GradientStop Offset="0" Color="#FF9900"/>
                                                            <GradientStop Offset="0.499" Color="#FF9900"/>
                                                            <GradientStop Offset="0.501" Color="#FF0000"/>
                                                            <GradientStop Offset="1" Color="#FF0000"/>
                                                        </LinearGradientBrush>
                                                    </Setter.Value>
                                                </Setter>
                                            </Trigger>

                                            <Trigger Property="IsPressed" Value="true">
                                                <Setter TargetName="imageFill" Property="Fill">
                                                    <Setter.Value>
                                                        <LinearGradientBrush StartPoint="0, 0.5" EndPoint="1, 0.5">
                                                            <GradientStop Offset="0" Color="#00CC00"/>
                                                            <GradientStop Offset="0.499" Color="#00CC00"/>
                                                            <GradientStop Offset="0.501" Color="#006600"/>
                                                            <GradientStop Offset="1" Color="#006600"/>
                                                        </LinearGradientBrush>
                                                    </Setter.Value>
                                                </Setter>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>

                        <Style x:Key="TrackButton" TargetType="{x:Type RepeatButton}">
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                        <Rectangle Fill="Transparent"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ControlTemplate.Resources>

                    <Grid x:Name="GridRoot" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
                        <Grid.RowDefinitions>
                            <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
                            <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
                        </Grid.RowDefinitions>

                        <Border Grid.RowSpan="4" BorderThickness="1" BorderBrush="#999999" CornerRadius="0, 5, 5, 0" Background="White"/>

                        <RepeatButton x:Name="DecreaseRepeat" Style="{DynamicResource ArrowButton}" Command="ScrollBar.LineUpCommand" Tag="Up"/>

                        <Track Grid.Row="1" x:Name="PART_Track" Orientation="Vertical" IsDirectionReversed="true">
                            <Track.Thumb>
                                <Thumb Focusable="False">
                                    <Thumb.Template>
                                        <ControlTemplate TargetType="{x:Type Thumb}">
                                            <Grid Margin="3, 0, 3, 0" Background="#98BFFE">
                                                <Rectangle Stroke="#999999" StrokeThickness="1" Fill="{x:Null}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                                                <Rectangle Fill="#333333" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="1"/>
                                                <Rectangle Fill="#666666" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="1"/>
                                                <Grid VerticalAlignment="Stretch" Margin="3, 2, 3, 2">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="*"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition MaxHeight="1"/>
                                                        <RowDefinition Height="*"/>
                                                    </Grid.RowDefinitions>
                                                    <Rectangle Grid.Row="1" Fill="#BBDDFF"/>
                                                    <Rectangle Grid.Row="2" Fill="#74A8FE"/>
                                                    <Rectangle Grid.Row="3" Fill="Transparent"/>
                                                    <Rectangle Grid.Row="4" Fill="#BBDDFF"/>
                                                    <Rectangle Grid.Row="5" Fill="#74A8FE"/>
                                                    <Rectangle Grid.Row="6" Fill="Transparent"/>
                                                    <Rectangle Grid.Row="7" Fill="#BBDDFF"/>
                                                    <Rectangle Grid.Row="8" Fill="#74A8FE"/>
                                                </Grid>
                                            </Grid>
                                        </ControlTemplate>
                                    </Thumb.Template>
                                </Thumb>
                            </Track.Thumb>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton x:Name="PageUp" Command="ScrollBar.PageDownCommand" Style="{StaticResource TrackButton}"/>
                            </Track.IncreaseRepeatButton>
                            <Track.DecreaseRepeatButton>
                                <RepeatButton x:Name="PageDown" Command="ScrollBar.PageUpCommand" Style="{StaticResource TrackButton}"/>
                            </Track.DecreaseRepeatButton>
                        </Track>

                        <RepeatButton Grid.Row="2" x:Name="IncreaseRepeat" Style="{DynamicResource ArrowButton}" Command="ScrollBar.LineDownCommand" Tag="Down"/>

                        <RepeatButton Grid.Row="3" x:Name="ToTheEndRepeat" Style="{DynamicResource ArrowButton}" Command="ScrollBar.ScrollToBottomCommand" Tag="ToTheEnd"/>

                        <Rectangle x:Name="DisabledElement" Grid.RowSpan="4" Fill="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" Visibility="Hidden"/>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Horizontal">
                            <Setter Property="LayoutTransform" TargetName="GridRoot">
                                <Setter.Value>
                                    <TransformGroup>
                                        <RotateTransform Angle="-90"/>
                                        <ScaleTransform ScaleY="-1"/>
                                    </TransformGroup>
                                </Setter.Value>
                            </Setter>

                            <Setter TargetName="PART_Track" Property="Orientation" Value="Vertical"/>

                            <Setter Property="Command" Value="ScrollBar.LineLeftCommand" TargetName="DecreaseRepeat"/>
                            <Setter Property="Command" Value="ScrollBar.LineRightCommand" TargetName="IncreaseRepeat"/>
                            <Setter Property="Command" Value="ScrollBar.ScrollToRightEndCommand" TargetName="ToTheEndRepeat"/>
                            <Setter Property="Command" Value="ScrollBar.PageLeftCommand" TargetName="PageDown"/>
                            <Setter Property="Command" Value="ScrollBar.PageRightCommand" TargetName="PageUp"/>
                        </Trigger>

                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="DisabledElement" Property="Visibility" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>